package com.horoscope.astrology.zodiac.signs.free.utils

object StringUtils {
    fun newLineStr(name: String): String {
        if (SysUtils.isContainChinese(name)) {
            val byteSize = name.toByteArray().size
            val newByte = ByteArray(18)
            if (byteSize > 18) {
                for (i in 0..17) {
                    newByte[i] = name.toByteArray()[i]
                }
                return String(newByte) + "..."
            }
        }

        return when {
            name.length in 21..40 -> {
                name.substring(0, 20) + "\n" + name.substring(20, name.length)
            }
            name.length >= 61 -> {
                name.substring(0, 20) + "\n" + name.substring(20, 41) + "\n" + name.substring(
                    41,
                    60
                ) +
                        "\n" + name.substring(60, name.length)
            }
            else -> {
                name
            }
        }
    }
}